package com.nettytime.util.testjiebaonianbaos;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.FixedLengthFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;

public class ChildServerFixedLengthChannelHandler extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 这里将FixedLengthFrameDecoder解码指定长度为100
        ch.pipeline().addLast(new FixedLengthFrameDecoder(100));
        // 将前一步解码的数据转码为字符串
        ch.pipeline().addLast(new StringDecoder());
        // 这里FixedLengthMessageEncoder是我们自定义的，用于将长度不足16的消息进行补全空格
        ch.pipeline().addLast(new FixedLengthMessageEncoder(100));
        // 最终的数据处理
        ch.pipeline().addLast(new NettyServerHandler());
    }
}